<template>
  <div>
    <div class="el-card operate-container is-never-shadow">
      <div class="el-card__body">
        <i class="el-icon-tickets"></i>
        <span>数据列表</span>
        <button class="btn-add el-button--default el-button--mini btn_right">添加</button>
      </div>
    </div>
    <div style="margin-top: 20px">
      <template>
        <el-table :data="GoodsType" border style="width: 100%">
          <el-table-column prop="id" label="编号" align="center"> </el-table-column>
          <el-table-column prop="name" label="类型名称 " align="center"> </el-table-column>
          <el-table-column prop="attributeCount" label="属性数量" align="center"> </el-table-column>
          <el-table-column prop="paramCount" label="参数数量" align="center"> </el-table-column>
          <el-table-column prop="address" label="设置" align="center" width="200px">
            <el-button size="mini">属性列表</el-button>
            <el-button size="mini">参数列表</el-button>
          </el-table-column>
          <el-table-column prop="address" label="操作" align="center">
            <template slot-scope="scope">
              <div>
                <el-button size="mini" @click="open(scope.row.name)">编辑</el-button>
                <el-button type="danger" size="mini" @click="removeItem(scope.row.id)">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <div class="block" style="float: right; margin-top: 20px">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[5, 10, 15]"
        :page-size="pageInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageInfo.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { fetchGoodsType } from '@/api/api'
export default {
  data() {
    return {
      value1: true,
      GoodsType: [],
      // 分页 总条数
      pageInfo: {
        // 每页多少条
        pageSize: 0,
        // 当前页
        currentPage: null,
        // 总条数
        total: 0,
      },
      currentPage4: 5,
    }
  },
  methods: {
    handleCurrentChange(val) {
      this.pageInfo.currentPage = val
      fetchGoodsType(val, 5).then((res) => {
        this.pageInfo.pageSize = res.data.pageSize
        this.GoodsType = res.data.list
      })
    },
    open(name) {
      this.$prompt('类型名称', '编辑类型', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValue: name,
      }).then(() => {
        this.$message({
          type: 'success',
          message: '修改成功',
        })
      })
    },
    removeItem(id) {
      this.GoodsType = this.GoodsType.filter((item) => item.id !== id)
    },
  },
  created() {
    fetchGoodsType(this.pageInfo.currentPage, 5).then((res) => {
      this.GoodsType = res.data.list
      this.pageInfo.total = res.data.total
    })
  },
}
</script>

<style lang="scss">
.el-message-box {
  width: 30%;
  margin-top: 15vh;
}
.el-card__body {
  border: 1px solid #ebeef5;
}
.btn-add {
  border: 1px solid #dcdfe6;
  background: #fff;
}
.btn_right {
  float: right;
}
.el-button--mini,
.el-button--small {
  font-size: 12px;
  border-radius: 3px;
}
</style>
